home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Internet Info 1994 March
/
Internet Info CD-ROM (Walnut Creek) (March 1994).iso
/
networking
/
ip
/
ka9q
/
MNetsrc.hqx
/
Mac TCP_IP Source v.33
/
main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-04-01
|
27KB
|
1,242 lines
/* Main network program - provides both client and server functions */
#define HOSTNAMELEN 32 /* changed from 16 by Bdale 860812 */
extern char startup[]; /* File to read startup commands from */
#include <stdio.h>
#include "global.h"
#include "config.h"
#include "mbuf.h"
#include "netuser.h"
#include "timer.h"
#include "icmp.h"
#include "iface.h"
#include "ip.h"
#include "tcp.h"
#include "ax25.h"
#include "netrom.h"
#ifdef MAC
#include "MacBinary.h"
#endif
#include "ftp.h"
#include "telnet.h"
#include "remote.h"
#include "session.h"
#include "cmdparse.h"
#ifdef ASY
#include "asy.h"
#include "slip.h"
#endif
#ifdef NRS
#include "nrs.h"
#endif
#ifdef UNIX /* BSD or SYS5 */
#include "unix.h"
#endif
#ifdef AMIGA
#include "amiga.h"
#endif
#ifdef MAC
#include "mac.h"
#include "mac_fopenw.h"
#include <time.h>
#endif
#ifdef MSDOS
#include "asy.h"
#endif
#ifdef TRACE
#include "trace.h"
/* Dummy structure for loopback tracing */
struct interface loopback = { NULLIF, "loopback" };
#endif
extern struct interface *ifaces;
extern char version[];
extern struct mbuf *loopq;
#ifdef MAC
#define itemdisable 0L
#define itemenable 1L
#define itemcheck 2L
#define itemuncheck 3L
extern char applroot[],mailqdir[],logname[],applestring[];
extern long timezone;
SysEnvRec *sysenvn;
static int tzoffset=0;
FILE *logwndp;
FILE *trcwndp;
FILE *stdiowndp;
StdWindowRec *stdiowrec;
StdWindowRec *logwrec;
StdWindowRec *trcwrec;
StdWindowOptions Macwindop,*Macwndops;
int tcptrcflg = FALSE;
Point wherestdio;
#endif
#ifdef CALLBK
FILE *cbkfp;
FILE *cbklfp;
extern char callbook[],calllog[];
#endif
int mode;
FILE *logfp;
char badhost[] = "Unknown host %s\n";
char hostname[HOSTNAMELEN];
unsigned nsessions = NSESSIONS;
int32 resolve();
int16 lport = 1001;
char prompt[] = "net> ";
char nospace[] = "No space!!\n"; /* Generic malloc fail message */
#ifndef MSDOS /* PC uses F-10 key always */
#ifdef MAC
static char escape = 0x1b; /* default escape character is "esc" */
#else
static char escape = 0x1d; /* default escape character is ^] */
#endif
#endif
/* Command lookup and branch table */
int go(),doax25(),cmdmode(),doconnect(),dotelnet(),doexit(),doclose(),
dohostname(),doreset(),dotcp(),dotrace(),doescape(),dohelp(),
doroute(),doecho(),dolog(),doip(),doetherstat(),
#ifdef MAC
doarp(),dosession(),doftp(),dostart(),dostop(),doattach(),
#else
memstat(),doarp(),dosession(),doftp(),dostart(),dostop(),doattach(),
#endif
dosmtp(),doudp(),doparam(),doeol(),dohapnstat(),
#ifdef MAC
doegstat(),dodump(),dorecord(),doupload(),dokick(),domode(),
#else
doegstat(),dodump(),dorecord(),doupload(),dokick(),domode(),doshell(),
#endif
dodir(),docd(),doatstat(),doping(),doforward(),doremote(),donetrom(),
#ifdef PROXY
donrstat(), dombox(), dois_es() ;
#else
donrstat(), dombox() ;
#endif
#ifdef _FINGER
int dofinger();
#endif
#ifdef MAC
int dotzone();
#endif
#ifdef CALLBK
int docallbk();
#endif
static struct cmds cmds[] = {
/* The "go" command must be first */
"", go, 0, NULLCHAR, NULLCHAR,
#ifndef MAC
"!", doshell, 0, NULLCHAR, NULLCHAR,
#endif
#if (defined(MAC) && defined(APPLETALK))
"applestat", doatstat, 0, NULLCHAR, NULLCHAR,
#endif
#if (defined(AX25) || defined(ETHER) || defined(APPLETALK))
"arp", doarp, 0, NULLCHAR, NULLCHAR,
#endif
#ifdef AX25
"ax25", doax25, 0, NULLCHAR, NULLCHAR,
#endif
"attach", doattach, 2,
"attach <hardware> <hw specific options>", NULLCHAR,
/* This one is out of alpabetical order to allow abbreviation to "c" */
#ifdef AX25
"connect", doconnect, 3,"connect <interface> <callsign> [digipeaters]",
NULLCHAR,
#endif
#ifdef CALLBK
"callbk", docallbk, 0, NULLCHAR, NULLCHAR,
#endif
#ifndef UNIX /* BSD or SYS5 */
"cd", docd, 0, NULLCHAR, NULLCHAR,
#endif
"close", doclose, 0, NULLCHAR, NULLCHAR,
"disconnect", doclose, 0, NULLCHAR, NULLCHAR,
"dir", dodir, 0, NULLCHAR, NULLCHAR,
#ifdef EAGLE
"eaglestat", doegstat, 0, NULLCHAR, NULLCHAR,
#endif
"echo", doecho, 0, NULLCHAR, "echo [refuse|accept]",
"eol", doeol, 0, NULLCHAR,
"eol options: unix, standard",
#ifndef MSDOS
"escape", doescape, 0, NULLCHAR, NULLCHAR,
#endif
#ifdef PC_EC
"etherstat", doetherstat, 0, NULLCHAR, NULLCHAR,
#endif PC_EC
"exit", doexit, 0, NULLCHAR, NULLCHAR,
#ifdef _FINGER
"finger", dofinger, 0, NULLCHAR, NULLCHAR,
#endif
"forward", doforward, 0, NULLCHAR, NULLCHAR,
"ftp", doftp, 2, "ftp <address>", NULLCHAR,
#ifdef HAPN
"hapnstat", dohapnstat, 0, NULLCHAR, NULLCHAR,
#endif HAPN
"help", dohelp, 0, NULLCHAR, NULLCHAR,
"hostname", dohostname, 0, NULLCHAR, NULLCHAR,
"kick", dokick, 0, NULLCHAR, NULLCHAR,
"log", dolog, 0, NULLCHAR, NULLCHAR,
"ip", doip, 0, NULLCHAR, NULLCHAR,
#ifdef PROXY
"is_es", dois_es, 0, NULLCHAR, NULLCHAR,
#endif
#ifndef MAC
"memstat", memstat, 0, NULLCHAR, NULLCHAR,
#endif
#ifdef AX25
"mbox", dombox, 0, NULLCHAR, NULLCHAR,
"mode", domode, 2, "mode <interface>", NULLCHAR,
#endif
#ifdef NETROM
"netrom", donetrom, 0, NULLCHAR, NULLCHAR,
#ifdef NRS
"nrstat", donrstat, 0, NULLCHAR, NULLCHAR,
#endif
#endif
"param", doparam, 2, "param <interface>", NULLCHAR,
"ping", doping, 0, NULLCHAR, NULLCHAR,
#ifndef UNIX /* BSD or SYS5 */
"pwd", docd, 0, NULLCHAR, NULLCHAR,
#endif
"record", dorecord, 0, NULLCHAR, NULLCHAR,
"remote", doremote, 4, "remote <address> <port> <command>",
NULLCHAR,
"reset", doreset, 0, NULLCHAR, NULLCHAR,
"route", doroute, 0, NULLCHAR, NULLCHAR,
"session", dosession, 0, NULLCHAR, NULLCHAR,
#ifndef MAC
"shell", doshell, 0, NULLCHAR, NULLCHAR,
#endif
"smtp", dosmtp, 0, NULLCHAR, NULLCHAR,
#ifdef SERVERS
"start", dostart, 2, "start <servername>",NULLCHAR,
"stop", dostop, 2, "stop <servername>", NULLCHAR,
#endif
"tcp", dotcp, 0, NULLCHAR, NULLCHAR,
"telnet", dotelnet, 2, "telnet <address>", NULLCHAR,
#ifdef TRACE
"trace", dotrace, 0, NULLCHAR, NULLCHAR,
#endif
#ifdef MAC
"tzone", dotzone, 0, NULLCHAR, NULLCHAR,
#endif
"udp", doudp, 0, NULLCHAR, NULLCHAR,
"upload", doupload, 0, NULLCHAR, NULLCHAR,
"?", dohelp, 0, NULLCHAR, NULLCHAR,
NULLCHAR, NULLFP, 0,
"Unknown command; type \"?\" for list", NULLCHAR,
};
#ifdef SERVERS
/* "start" and "stop" subcommands */
int dis1(),echo1(),ftp1(),smtp1(),tn1(),rem1();
#ifdef _FINGER
int finger1();
#endif
static struct cmds startcmds[] = {
"discard", dis1, 0, NULLCHAR, NULLCHAR,
"echo", echo1, 0, NULLCHAR, NULLCHAR,
#ifdef _FINGER
"finger", finger1, 0, NULLCHAR, NULLCHAR,
#endif
"ftp", ftp1, 0, NULLCHAR, NULLCHAR,
"smtp", smtp1, 0, NULLCHAR, NULLCHAR,
"telnet", tn1, 0, NULLCHAR, NULLCHAR,
"remote", rem1, 0, NULLCHAR, NULLCHAR,
NULLCHAR, NULLFP, 0,
#ifdef _FINGER
"start options: discard, echo, finger, ftp, smtp, telnet", NULLCHAR,
#else
"start options: discard, echo, ftp, smtp, telnet", NULLCHAR,
#endif
};
int ftp_stop(),smtp_stop(),echo_stop(),dis_stop(),tn_stop();
int dis0(),echo0(),ftp0(),smtp0(),tn0(),rem0();
#ifdef _FINGER
int finger0();
#endif
static struct cmds stopcmds[] = {
"discard", dis0, 0, NULLCHAR, NULLCHAR,
"echo", echo0, 0, NULLCHAR, NULLCHAR,
#ifdef _FINGER
"finger", finger0, 0, NULLCHAR, NULLCHAR,
#endif
"ftp", ftp0, 0, NULLCHAR, NULLCHAR,
"smtp", smtp0, 0, NULLCHAR, NULLCHAR,
"telnet", tn0, 0, NULLCHAR, NULLCHAR,
"remote", rem0, 0, NULLCHAR, NULLCHAR,
NULLCHAR, NULLFP, 0,
#ifdef _FINGER
"stop options: discard, echo, finger, ftp, smtp, telnet", NULLCHAR,
#else
"stop options: discard, echo, ftp, smtp, telnet", NULLCHAR,
#endif
};
#endif
main(argc,argv)
int argc;
char *argv[];
{
static char inbuf[BUFSIZ]; /* keep it off the stack */
#ifdef MAC
int c,e;
int i,memErrResult;
void mac_aboutcmd(),MacHelp(),mac_quits(),mac_windows();
#endif
char *ttybuf,*fgets(),*cp;
int16 cnt;
int ttydriv();
int cmdparse();
void check_time(),ip_recv();
FILE *fp;
struct interface *ifp;
struct mbuf *bp;
#ifdef MAC
SetApplLimit(((Ptr *)GetApplLimit)-32767);
MaxApplZone();
for (i=1;i<=5;i++) /*allocate some more blocks ($100) of master pointers*/
{
memErrResult = MemError(); /* test for memory manager error*/
if (memErrResult == noErr)
{
MoreMasters();
memErrResult = MemError(); /*test for memory manager error*/
}
} /*end of 'for'*/
if (memErrResult != noErr){ /*test if terminated by error*/
printf("main: Not enough memory to continue.\n"); /*out of memory..*/
exit(-1);
}
mac_tools("About KA9Q Internet..");
menu (applestring,"About KA9Q Internet..",mac_aboutcmd);
menu (applestring,"Help",MacHelp);
menu ("File","-",itemdisable);
menu ("File","Quit/Q",mac_quits);
menu ("Edit", "Undo", (ProcPtr)itemdisable);
menu ("Edit", "Cut/X", (ProcPtr)itemdisable);
menu ("Edit", "Copy/C", (ProcPtr)itemdisable);
menu ("Edit", "Paste/V", (ProcPtr)itemdisable);
menu ("Edit", "Clear", (ProcPtr)itemdisable);
menu ("Windows","Console",itemenable);
menu ("Windows","Console",mac_windows);
menu ("Windows","Log",itemdisable);
menu ("Windows","Log",mac_windows);
menu ("Windows","Trace",itemdisable);
menu ("Windows","Trace",mac_windows);
Macwindop.maxrow = 24; /* Initialize stdio window options */
Macwindop.maxcol = 80;
Macwindop.cursor_visible = TRUE;
Macwindop.echo_state = TRUE;
Macwindop._tab_width = 4;
Macwindop.no_pull_front = TRUE;
Macwindop.no_grow = FALSE;
Macwindop.no_drag = FALSE;
Macwindop.no_goaway = TRUE;
Macwindop.no_scroll = FALSE;
Macwindop.no_wrap = FALSE;
Macwndops = &Macwindop;
wherestdio.h=4;
wherestdio.v=_MBARHEIGHT + _TITLEBARHEIGHT + 4;
Stdio_MacInit(true);
stdiowrec = Get_WindowPtr(stdout); /* set options on stdio window */
stdiowrec->opt.no_pull_front = TRUE;
if ( ( e = SysEnvirons(1,sysenvn) ) != 0) /* Get local environment info */
{
printf("main: could not get the local environment info.\n");
exit(-1);
}
#endif
ioinit();
#ifdef MAC
_closeall(); /* Make sure all is ok after a crash */
#endif
#if (defined(UNIX) || defined(AMIGA) || defined(MAC))
#else
chktasker();
#endif
#ifdef MSDOS
printf("KA9Q Internet Protocol Package, v%s DS = %x\n",version,
getds());
#else
printf("KA9Q Internet Protocol Package, v%s\n",version);
#endif
printf("Copyright 1988 by Phil Karn, KA9Q\n");
#ifdef NETROM
printf("NET/ROM Support Copyright 1989 by Dan Frank, W9NK\n") ;
#endif
sessions = (struct session *)calloc(nsessions,sizeof(struct session));
if(argc > 1){
/* Read startup file named on command line */
fp = fopen(argv[1],"r");
} else {
fp = fopen(startup,"r");
}
#ifdef MAC
if ( fp == NULLFILE) /* Check for existence of net.start */
{
printf("main: could not find net.start.\n");
exit(-1);
}
#endif
if(fp != NULLFILE){
while(fgets(inbuf,BUFSIZ,fp) != NULLCHAR){
cmdparse(cmds,inbuf);
}
fclose(fp);
}
#ifdef MAC
SelectWindow(stdiowrec); /* Make console the front window */
#endif
cmdmode();
/* Main commutator loop */
for(;;){
/* Process any keyboard input */
#ifdef MAC
while ((c = mac_toolsevents()) != -1){
#else
while((c = kbread()) != -1){
#endif
#ifdef MSDOS
/* c == -2 means the command escape key (F10) */
if(c == -2){
if(mode != CMD_MODE){
printf("\n");
cmdmode();
}
continue;
}
#endif
#ifdef SYS5
if(c == escape && escape != 0){
if(mode != CMD_MODE){
printf("\r\n");
cmdmode();
}
continue;
}
#endif /* SYS5 */
#ifdef MAC
if(c == escape && escape != 0){
if(mode != CMD_MODE){
printf("\n");
cmdmode();
}
continue;
}
#endif
if((cnt = ttydriv(c,&ttybuf)) == 0)
continue;
switch(mode){
case CMD_MODE:
(void)cmdparse(cmds,ttybuf);
fflush(stdout);
break;
case CONV_MODE:
#ifndef MSDOS
if(ttybuf[0] == escape && escape != 0){
printf("\n");
cmdmode();
} else
#endif MSDOS
if(current->parse != NULLFP)
(*current->parse)(ttybuf,cnt);
break;
}
if(mode == CMD_MODE){
printf(prompt);
fflush(stdout);
}
}
/* Service the loopback queue */
if((bp = dequeue(&loopq)) != NULLBUF){
struct ip ip;
#ifdef TRACE
dump(&loopback,IF_TRACE_IN,TRACE_IP,bp);
#endif
/* Extract IP header */
ntohip(&ip,&bp);
ip_recv(&ip,bp,0);
}
/* Service the interfaces */
for(ifp = ifaces; ifp != NULLIF; ifp = ifp->next){
if(ifp->recv != NULLVFP)
(*ifp->recv)(ifp);
}
/* Service the clock if it has ticked */
check_time();
#ifdef MSDOS
/* Tell DoubleDos to let the other task run for awhile.
* If DoubleDos isn't active, this is a no-op
*/
giveup();
#else
/* Wait until interrupt, then do it all over again */
#ifndef MAC
eihalt();
#endif
#endif
}
}
/* Standard commands called from main */
/* Enter command mode */
int
cmdmode()
{
if(mode != CMD_MODE){
mode = CMD_MODE;
cooked();
printf(prompt);
fflush(stdout);
}
return 0;
}
static
doexit(argc,argv)
int argc;
char *argv[];
{
if(logfp != NULLFILE)
fclose(logfp);
iostop();
exit(0);
}
static
dohostname(argc,argv)
int argc;
char *argv[];
{
char *strncpy();
if(argc < 2)
printf("%s\n",hostname);
else
strncpy(hostname,argv[1],HOSTNAMELEN);
return 0;
}
static
int
dolog(argc,argv)
int argc;
char *argv[];
{
char *pathname(),*strcpy();
char *ptr;
Point wherelog;
wherelog.h=4;
wherelog.v=_MBARHEIGHT + _TITLEBARHEIGHT + 4;
if (argc > 1) {
if(logfp){ /* close existing log file */
fclose(logfp);
logfp = NULLFILE;
}
if(logwndp){
fclose(logwndp);
menu ("Windows","Log",itemdisable);
logwndp = NULLFILE;
}
if(strcmp(argv[1],"stop") != 0){
ptr = pathname(logname,argv[1]);
strcpy(logname,ptr);
(void)free(ptr);
logfp = fopen(logname,"a");
if(logfp == NULLFILE) {
printf("Couldn't open log file '%s'.\n",logname);
strcpy(logname,applroot); /* reset initial path */
}
logwndp = fopenw("Log",wherelog,Macwndops);
logwrec = Get_WindowPtr(logwndp);
menu ("Windows","Log",itemenable);
}
}
if(logfp)
printf("Logging to '%s'.\n",logname);
else
printf("Logging off\n");
return 0;
}
static
int
dohelp(argc,argv)
int argc;
char *argv[];
{
#ifdef MAC
DoHelp("\p","\pKA9Q Internet Software","\pApple Macintosh Version",
"\p⌐ Copyright 1988, Phil Karn",TRUE,0L);
DisposeHelp();
#else
register struct cmds *cmdp;
int i,j;
printf("Main commands:\n");
for(i=0,cmdp = cmds;cmdp->name != NULL;cmdp++,i++){
printf("%s",cmdp->name);
if((i % 4) == 3)
printf("\n");
else {
for(j=strlen(cmdp->name);j < 16; j++)
putchar(' ');
}
}
if((i % 4) != 0)
printf("\n");
return 0;
#endif
}
doecho(argc,argv)
int argc;
char *argv[];
{
extern int refuse_echo;
if(argc < 2){
if(refuse_echo)
printf("Refuse\n");
else
printf("Accept\n");
} else {
if(argv[1][0] == 'r')
refuse_echo = 1;
else if(argv[1][0] == 'a')
refuse_echo = 0;
else
return -1;
}
return 0;
}
/* set for unix end of line for remote echo mode telnet */
doeol(argc,argv)
int argc;
char *argv[];
{
extern int unix_line_mode;
if(argc < 2){
if(unix_line_mode)
printf("Unix\n");
else
printf("Standard\n");
} else {
if(strcmp(argv[1],"unix") == 0)
unix_line_mode = 1;
else if(strcmp(argv[1],"standard") == 0)
unix_line_mode = 0;
else {
return -1;
}
}
return 0;
}
/* Attach an interface
* Syntax: attach <hw type> <I/O address> <vector> <mode> <label> <bufsize> [<speed>]
*/
doattach(argc,argv)
int argc;
char *argv[];
{
extern struct cmds attab[];
return subcmd(attab,argc,argv);
}
/* Manipulate I/O device parameters */
doparam(argc,argv)
int argc;
char *argv[];
{
register struct interface *ifp;
for(ifp=ifaces;ifp != NULLIF;ifp = ifp->next){
if(strcmp(argv[1],ifp->name) == 0)
break;
}
if(ifp == NULLIF){
printf("Interface \"%s\" unknown\n",argv[1]);
return 1;
}
if(ifp->ioctl == NULLFP){
printf("Not supported\n");
return 1;
}
/* Pass rest of args to device-specific code */
return (*ifp->ioctl)(ifp,argc-2,argv+2);
}
/* Log messages of the form
* Tue Jan 31 00:00:00 1987 44.64.0.7:1003 open FTP
*/
/*VARARGS2*/
log(tcb,fmt,arg1,arg2,arg3,arg4)
struct tcb *tcb;
char *fmt;
#ifdef MAC
char *arg1,*arg2,*arg3,*arg4; /* everything should come as 32-bit */
#else
int arg1,arg2,arg3,arg4; /* original non-Mac code */
#endif
{
char *logtime();
int fd;
if(logfp == NULLFILE)
return;
fprintf(logfp,"%s %s - ",logtime(),psocket(&tcb->conn.remote));
fprintf(logfp,fmt,arg1,arg2,arg3,arg4);
fprintf(logfp,"\n");
fflush(logfp);
fprintf(logwndp,"%s %s - ",logtime(),psocket(&tcb->conn.remote));
fprintf(logwndp,fmt,arg1,arg2,arg3,arg4);
fprintf(logwndp,"\n");
#ifdef MSDOS
/* MS-DOS doesn't really flush files until they're closed */
fd = fileno(logfp);
if((fd = dup(fd)) != -1)
close(fd);
#endif
}
/* support function for above logging (used elsewhere for console
* reporting) - returns a character pointer to a time string.
*/
char *
logtime()
{
long t;
char *cp;
time(&t); /* get time */
cp = ctime(&t); /* turn into a string */
rip(cp); /* remove trailing \n, replace with \0 */
return(cp); /* return the pointer */
}
/* Configuration-dependent code */
/* List of supported hardware devices */
int ec_attach(),asy_attach(),pc_attach(),eg_attach(),hapn_attach(),at_attach(),
nr_attach(),pk_attach();
struct cmds attab[] = {
#ifdef PC_EC
/* 3-Com Ethernet interface */
"3c500", ec_attach, 7,
"attach 3c500 <address> <vector> arpa <label> <buffers> <mtu>",
"Could not attach 3c500",
#endif
#ifdef ASY
/* Ordinary PC asynchronous adaptor */
"asy", asy_attach, 8,
"attach asy <address> <vector> slip|ax25|nrs <label> <buffers> <mtu> <speed>",
"Could not attach asy",
#endif
#ifdef PC100
/* PACCOMM PC-100 8530 HDLC adaptor */
"pc100", pc_attach, 8,
"attach pc100 <address> <vector> ax25 <label> <buffers> <mtu> <speed>",
"Could not attach pc100",
#endif
#ifdef EAGLE
/* EAGLE RS-232C 8530 HDLC adaptor */
"eagle", eg_attach, 8,
"attach eagle <address> <vector> ax25 <label> <buffers> <mtu> <speed>",
"Could not attach eagle",
#endif
#ifdef HAPN
/* Hamilton Area Packet Radio (HAPN) 8273 HDLC adaptor */
"hapn", hapn_attach, 8,
"attach hapn <address> <vector> ax25 <label> <rx bufsize> <mtu> csma|full",
"Could not attach hapn",
#endif
#ifdef APPLETALK
/* Macintosh AppleTalk */
"appletalk", at_attach, 7,
"attach appletalk <protocol type> <device> arpa <label> <rx bufsize> <mtu>",
"Could not attach Appletalk",
#endif
#ifdef NETROM
/* fake netrom interface */
"netrom", nr_attach, 1,
"attach netrom",
"Could not attach netrom",
#endif
#ifdef PACKET
/* FTP Software's packet driver spec */
"packet", pk_attach, 4,
"attach packet <int#> <label> <buffers> <mtu>",
"Could not attach packet driver",
#endif
NULLCHAR, NULLFP, 0,
"Unknown device",
NULLCHAR,
};
/* Protocol tracing function pointers */
#ifdef TRACE
int ax25_dump(),ether_dump(),ip_dump(),at_dump();
int (*tracef[])() = {
#ifdef AX25
ax25_dump,
#else
NULLFP,
#endif
#ifdef ETHER
ether_dump,
#else
NULLFP,
#endif
ip_dump,
#ifdef APPLETALK
at_dump,
#else
NULLFP,
#endif
};
#else
int (*tracef[])() = { NULLFP }; /* No tracing at all */
dump(interface,direction,type,bp)
struct interface *interface;
int direction;
unsigned type;
struct mbuf *bp;
{
}
#endif
#ifdef ASY
/* Attach a serial interface to the system
* argv[0]: hardware type, must be "asy"
* argv[1]: I/O address, e.g., "0x3f8"
* argv[2]: vector, e.g., "4"
* argv[3]: mode, may be:
* "slip" (point-to-point SLIP)
* "ax25" (AX.25 frame format in SLIP for raw TNC)
* "nrs" (NET/ROM format serial protocol)
* argv[4]: interface label, e.g., "sl0"
* argv[5]: receiver ring buffer size in bytes
* argv[6]: maximum transmission unit, bytes
* argv[7]: interface speed, e.g, "9600"
* argv[8]: optional ax.25 callsign (NRS only)
*/
int
asy_attach(argc,argv)
int argc;
char *argv[];
{
register struct interface *if_asy;
extern struct interface *ifaces;
int16 dev;
int mode;
int asy_init();
int asy_send();
int asy_ioctl();
void doslip();
int asy_stop();
int ax_send();
int ax_output();
void kiss_recv();
int kiss_raw();
int kiss_ioctl();
int slip_send();
void slip_recv();
int slip_raw();
struct ax25_addr addr ;
int ax_send(),ax_output(),nrs_raw(),asy_ioctl();
void nrs_recv();
if(nasy >= ASY_MAX){
printf("Too many asynch controllers\n");
return -1;
}
if(strcmp(argv[3],"slip") == 0)
mode = SLIP_MODE;
else if(strcmp(argv[3],"ax25") == 0)
mode = AX25_MODE;
else if(strcmp(argv[3],"nrs") == 0)
mode = NRS_MODE;
else
mode = UNKNOWN;
dev = nasy++;
/* Create interface structure and fill in details */
if_asy = (struct interface *)calloc(1,sizeof(struct interface));
if_asy->name = malloc((unsigned)strlen(argv[4])+1);
strcpy(if_asy->name,argv[4]);
if_asy->mtu = atoi(argv[6]);
if_asy->dev = dev;
if_asy->recv = doslip;
if_asy->stop = asy_stop;
switch(mode){
#ifdef SLIP
case SLIP_MODE:
if_asy->ioctl = asy_ioctl;
if_asy->send = slip_send;
if_asy->output = NULLFP; /* ARP isn't used */
if_asy->raw = slip_raw;
if_asy->flags = 0;
slip[dev].recv = slip_recv;
break;
#endif
#ifdef AX25
case AX25_MODE: /* Set up a SLIP link to use AX.25 */
axarp();
if(mycall.call[0] == '\0'){
printf("set mycall first\n");
free(if_asy->name);
free((char *)if_asy);
nasy--;
return -1;
}
if_asy->ioctl = kiss_ioctl;
if_asy->send = ax_send;
if_asy->output = ax_output;
if_asy->raw = kiss_raw;
if(if_asy->hwaddr == NULLCHAR)
if_asy->hwaddr = malloc(sizeof(mycall));
memcpy(if_asy->hwaddr,(char *)&mycall,sizeof(mycall));
slip[dev].recv = kiss_recv;
break;
#endif
#ifdef NRS
case NRS_MODE: /* Set up a net/rom serial interface */
if(argc < 9){
/* no call supplied? */
if(mycall.call[0] == '\0'){
/* try to use default */
printf("set mycall first or specify in attach statement\n");
return -1;
} else
addr = mycall;
} else {
/* callsign supplied on attach line */
if(setcall(&addr,argv[8]) == -1){
printf ("bad callsign on attach line\n");
free(if_asy->name);
free((char *)if_asy);
nasy--;
return -1;
}
}
if_asy->recv = nrs_recv;
if_asy->ioctl = asy_ioctl;
if_asy->send = ax_send;
if_asy->output = ax_output;
if_asy->raw = nrs_raw;
if(if_asy->hwaddr == NULLCHAR)
if_asy->hwaddr = malloc(sizeof(addr));
memcpy(if_asy->hwaddr,(char *)&addr,sizeof(addr));
nrs[dev].iface = if_asy;
break;
#endif
default:
printf("Mode %s unknown for interface %s\n",
argv[3],argv[4]);
free(if_asy->name);
free((char *)if_asy);
nasy--;
return -1;
}
if_asy->next = ifaces;
ifaces = if_asy;
asy_init(dev,argv[1],argv[2],(unsigned)atoi(argv[5]));
asy_speed(dev,atoi(argv[7]));
return 0;
}
#endif
#ifndef NETROM
#ifdef AX25
struct ax25_addr nr_nodebc;
#endif
nr_route(bp)
struct mbuf *bp;
{
free_p(bp);
}
nr_nodercv(bp)
{
free_p(bp);
}
#endif
/* Display or set IP interface control flags */
domode(argc,argv)
int argc;
char *argv[];
{
register struct interface *ifp;
for(ifp=ifaces;ifp != NULLIF;ifp = ifp->next){
if(strcmp(argv[1],ifp->name) == 0)
break;
}
if(ifp == NULLIF){
printf("Interface \"%s\" unknown\n",argv[1]);
return 1;
}
if(argc < 3){
printf("%s: %s\n",ifp->name,
(ifp->flags & CONNECT_MODE) ? "VC mode" : "Datagram mode");
return 0;
}
switch(argv[2][0]){
case 'v':
case 'c':
case 'V':
case 'C':
ifp->flags = CONNECT_MODE;
break;
case 'd':
case 'D':
ifp->flags = DATAGRAM_MODE;
break;
default:
printf("Usage: %s [vc | datagram]\n",argv[0]);
return 1;
}
return 0;
}
#ifdef SERVERS
dostart(argc,argv)
int argc;
char *argv[];
{
return subcmd(startcmds,argc,argv);
}
dostop(argc,argv)
int argc;
char *argv[];
{
return subcmd(stopcmds,argc,argv);
}
#endif SERVERS
#ifdef TRACE
static
int
dotrace(argc,argv)
int argc;
char *argv[];
{
struct interface *ifp;
if(argc < 2){
showtrace(&loopback);
for(ifp = ifaces; ifp != NULLIF; ifp = ifp->next)
showtrace(ifp);
return 0;
}
if(strcmp("loopback",argv[1]) == 0)
ifp = &loopback;
else
for(ifp = ifaces; ifp != NULLIF; ifp = ifp->next)
if(strcmp(ifp->name,argv[1]) == 0)
break;
if(ifp == NULLIF){
printf("Interface %s unknown\n",argv[1]);
return 1;
}
if(argc >= 3)
ifp->trace = htoi(argv[2]);
#ifdef MAC
if(ifp->trace == 0) {
tcptrcflg = FALSE;
menu ("Windows","Trace",itemdisable);
fclose(trcwndp);
}
else {
tcptrcflg = TRUE;
menu ("Windows","Trace",itemenable);
trcwndp = fopenw("Trace",wherestdio,Macwndops);
trcwrec = Get_WindowPtr(trcwndp);
}
#endif
showtrace(ifp);
return 0;
}
/* Display the trace flags for a particular interface */
static
showtrace(ifp)
register struct interface *ifp;
{
if(ifp == NULLIF)
return;
printf("%s:",ifp->name);
if(ifp->trace & (IF_TRACE_IN | IF_TRACE_OUT)){
if(ifp->trace & IF_TRACE_IN)
printf(" input");
if(ifp->trace & IF_TRACE_OUT)
printf(" output");
if(ifp->trace & IF_TRACE_HEX)
printf(" (Hex/ASCII dump)");
else if(ifp->trace & IF_TRACE_ASCII)
printf(" (ASCII dump)");
else
printf(" (headers only)");
printf("\n");
} else
printf(" tracing off\n");
fflush(stdout);
}
#endif
#ifndef MSDOS
static
int
doescape(argc,argv)
int argc;
char *argv[];
{
if(argc < 2)
printf("0x%x\n",escape);
else
escape = *argv[1];
return 0;
}
#endif MSDOS
static
doremote(argc,argv)
int argc;
char *argv[];
{
struct socket fsock,lsock;
struct mbuf *bp;
lsock.address = ip_addr;
fsock.address = resolve(argv[1]);
lsock.port = fsock.port = atoi(argv[2]);
bp = alloc_mbuf(1);
if(strcmp(argv[3],"reset") == 0){
*bp->data = SYS_RESET;
} else if(strcmp(argv[3],"exit") == 0){
*bp->data = SYS_EXIT;
} else {
printf("Unknown command %s\n",argv[3]);
return 1;
}
bp->cnt = 1;
send_udp(&lsock,&fsock,0,0,bp,0,0,0);
return 0;
}
#ifdef MAC
static
dotzone(argc,argv)
int argc;
char *argv[];
{
char *strncpy();
if(argc < 2)
printf("Time Zone = %s Offset = %d\n",tzname[1],tzoffset);
else {
strncpy(tzname[0],argv[1],3);
strncpy(tzname[1],argv[1],3);
tzoffset = atoi(argv[2]);
timezone = (tzoffset * 3600);
}
return 0;
}
#endif
#ifdef CALLBK
static
int
docallbk(argc,argv)
int argc;
char *argv[];
{
char *pathname(),*strcpy();
char *ptr;
if (argc > 1) {
ptr = pathname(applroot,argv[1]);
strcpy(callbook,ptr);
(void)free(ptr);
cbkfp = fopen(callbook,"r");
if(cbkfp == NULLFILE) {
printf("Callbook Server: Unable to open Callbook Server Database: '%s'.\n",callbook);
printf("Callbook Server: Not available.\n");
strcpy(callbook,applroot); /* reset initial path */
return 0;
}
if(argv[2] == NULLCHAR) {
printf("Callbook Server: Log not enabled.\n");
cbklfp = NULLFILE;
goto docalln;
}
ptr = pathname(applroot,argv[2]);
strcpy(calllog,ptr);
(void)free(ptr);
cbklfp = fopen(calllog,"a");
if(cbklfp == NULLFILE) {
printf("Callbook Server: Unable to open Callbook Server Log: '%s'.\n",callbook);
printf("Callbook Server: Logging not available.\n");
strcpy(calllog,applroot); /* reset initial path */
return 0;
}
}
docalln:
if((cbkfp != NULLFILE) && (cbklfp != NULLFILE)) {
printf("Callbook Server: Database = '%s'.\n\t\t\t\t Log = '%s'.\n",
callbook,calllog);
return 0;
}
if(cbkfp != NULLFILE) {
printf("Callbook Server: Database = '%s'\n",callbook);
return 0;
}
else {
printf("Callbook Server: Not available.\n");
return 0;
}
}
#endif